<?php
/**地区管理控制器
 * @Author: 976123967@qq.com
 * @Date:   2014-08-25 23:28:48
 * @Last Modified by:   chen
 * @Last Modified time: 2014-08-31 12:00:40
 */
class CityControl extends CommonControl{
	/**
	 * [__auto 初始化]
	 * @return [type] [description]
	 */
	public function __auto()
	{
		$this->model = K('City');
		// 分类树
		$city = $this->model->get_city_all();
		// 分配
		$this->assign('city',$city);
	}

	/**
	 * [index 所有地区]
	 * @return [type] [description]
	 */
	public function index()
	{

		if(IS_POST)
		{
			if(!$this->model->city_sort())
				$this->error($this->model->error);
			// 提示信息
			$this->success('地区排序成功',U('City/index'));
		}
		$this->display();
	}

	/**
	 * [add 添加地区]
	 */
	public function add()
	{
		if(IS_POST)
		{
			if(!$this->model->create()) $this->error($this->model->error);
			$this->model->add_city();
			$this->success('地区添加成功',U('City/index'));
		}
		$this->display();
	}


	/**
	 * [edit 编辑]
	 * @return [type] [description]
	 */
	public function edit()
	{
		if(IS_POST)
		{
			if(!$this->model->create()) $this->error($this->model->error);
			$this->model->save_city();
			$this->success('地区编辑成功',U('City/index'));
		}
		$lid = Q('get.lid',0,'intval');

		$data = $this->model->get_city_one($lid);
		if(!$data) $this->success('地区不存在',U('City/index'));

		$this->assign('data',$data);
		$this->display();
	}

	/**
	 * [del 删除]
	 * @return [type] [description]
	 */
	public function del()
	{
		$lid  = Q('get.lid',0,'inval');
		
		if(!$this->model->del_city($lid))  $this->error($this->model->error);

		$this->success('地区删除成功',U('City/index'));


	}



	/**
	 * [update_cache 更新商品分类缓存]
	 * @return [type] [description]
	 */
	public function update_cache()
	{
		// 执行模型中更新缓存
		$this->model->update_city_cache();
		// 提示信息
		$this->success('地区缓存更新成功',U('City/index'));
	}





}